/**
 * Copyright (c) 2018 qar All rights reserved.
 *
 * https://www.qar.io
 *
 * 版权所有，侵权必究！
 */

package com.example.service.impl;

//import com.example.mybatis.service.impl.BaseServiceImpl;
//import com.example.dao.SysLanguageDao;
//import com.example.entity.SysLanguageEntity;
//import com.example.service.SysLanguageService;
import com.example.dao.SysLanguageDao;
import com.example.entity.SysLanguageEntity;
import com.example.mybatis.service.impl.BaseServiceImpl;
import com.example.security.SecurityUser;
import com.example.service.SysLanguageService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 国际化
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service
public class SysLanguageServiceImpl extends BaseServiceImpl<SysLanguageDao, SysLanguageEntity> implements SysLanguageService {

    @Override
    public void saveOrUpdate(String tableName, Long tableId, String fieldName, String fieldValue, String language) {
        SysLanguageEntity entity = new SysLanguageEntity();
        entity.setTableName(tableName);
        entity.setTableId(tableId);
        entity.setFieldName(fieldName);
        entity.setFieldValue(fieldValue);

        entity.setLanguage(language);
        entity.setTenantId(SecurityUser.getTenantId());
        entity.setStoreId(SecurityUser.getStoreId());



        //判断是否有数据
        if(baseDao.getLanguage(entity) == null){
            baseDao.insert(entity);
        }else {
            entity.setUpdateDate(new Date());
            entity.setUpdator(SecurityUser.getUserId());
            baseDao.updateLanguage(entity);
        }
    }
}